#encoding=utf8
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
from sklearn.ensemble import RandomForestClassifier
from sklearn import cross_validation, metrics
from sklearn.model_selection import train_test_split


if __name__ == "__main__":
    mpl.rcParams['font.sans-serif'] = [u'SimHei']
    mpl.rcParams['axes.unicode_minus'] = False
    train = pd.read_csv('../dataset/train_modified.csv')
    target='Disbursed' # Disbursed的值就是二元分类的输出
    IDcol = 'ID'
    print train['Disbursed'].value_counts()

    x_columns = [x for x in train.columns if x not in [target, IDcol]]
    X = train[x_columns]
    y = train['Disbursed']

    x_train, x_test, y_train, y_test = train_test_split(X, y, train_size=0.7, random_state=1)

    # 随机森林
    rfc = RandomForestClassifier(n_estimators=200, criterion='entropy', max_depth=6)
    rfc.fit(x_train, y_train)

    y_pred = rfc.predict(x_test)
    y_predprob = rfc.predict_proba(x_test)[:, 1]
    print "Accuracy(Test) : %.4g" % metrics.accuracy_score(y_test.values, y_pred)
    print "AUC Score(Test): %f" % metrics.roc_auc_score(y_test, y_predprob)

